<?php

class BinaryTree 
{
	protected $_root;
	
	private $_string;
	
    public function __construct(BinaryTreeNode $root) 
    {
    	$this->_root = $root;
    }
    
    public function getIterator(TreeTraversable $traversable)
    {
    	return $traversable->traverseTree($this->_root);
    }
    
    public function isEmpty()
    {
    	return $this->_root == null;
    }
    
    public function __toString()
    {
    	$this->_string = null;
    	$this->_drawTree($this->_root);
    	return $this->_string;
    }
    
    private function _drawTree(BinaryTreeNode $node, $ret = '')
    {
		$this->_string .= ' ( ';
		$this->_string .= $node->getValue();
		if ($node->getLeft() != null){
			$this->_string .= $this->_drawTree($node->getLeft(), $ret);
		}else{
			$this->_string .= ' null ';
		}
		
		if ($node->getRight() != null){
			$this->_string .= $this->_drawTree($node->getRight(), $ret);
		}else{
			$this->_string .= ' null ';
		}    
		
		
		$this->_string .= ' ) ';    	
    }
} 
?>